package com.huaxin.hxenum.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxenum.base.BaseCodeEnum;

/**
 * 通知方式枚举类
 */
public enum NotificationType implements BaseCodeEnum<String> {

    SMS("sms", "短信"),
    APP_PUSH("app_push", "App推送"),
    EMAIL("email", "邮件"),
    IN_SYSTEM("in_system", "站内信");

    @EnumValue
    private final String code;
    private final String displayName;

    NotificationType(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public static NotificationType of(String code) {
        if (code == null) return null;
        for (NotificationType type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        return null;
    }

    public static boolean isValid(String code) {
        return of(code) != null;
    }
}
